package com.um.pasantiaum.cliente;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.um.pasantiaum.objetos.Producto;
import com.um.pasantiaum.objetos.UserManager;
import com.um.pasantiaum.objetos.Usuario;


public class CompanyManager {
	private ArrayList<Usuario> mUsers;
	private static CompanyManager sUserManager;
	private static ParseUser sCurrentUser;

	public static CompanyManager getCompanyManager(ParseUser currentUser) {
		if (sUserManager == null || !currentUser.equals(sCurrentUser))
			sUserManager = new CompanyManager(currentUser);
		return sUserManager;
	}

	private CompanyManager(ParseUser currentUser) {
		mUsers = new ArrayList<Usuario>();
		sCurrentUser = currentUser;
		
		ParseQuery<ParseObject> query = ParseQuery.getQuery("UserEmpresa");
		query.whereEqualTo("user", sCurrentUser);
		//query.whereEqualTo("isActive", true);
		query.include("empresa");

		try {
			List<ParseObject> objects = query.find();
			Log.d("SELECTCOMPANYACTIVITY", String.valueOf(objects.size()));
			for (ParseObject po : objects) {
				ParseUser temp = po.getParseUser("empresa");
				Log.d("SELECTCOMPANYACTIVITY", temp.getUsername());
				mUsers.add(new Usuario(temp));
			}

		} catch (ParseException e1) {
			Log.d("Usuario", "Error: " + e1.getMessage());
		}
	}

	
	public void removeUser(Usuario us) {

	}

	public ArrayList<Usuario> getUsers() {
		return mUsers;
	}

}
